//    https://ac.nowcoder.com/acm/contest/5600/I



#include <iostream>
#include <vector>
using namespace std;

typedef long long LL;
LL horizontal[1000004], vertical[1000004];

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<LL> > nm(n + 1, vector<LL>(m + 1));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            scanf("%lld", &nm[i][j]);
            horizontal[i] += nm[i][j];
        }

    for (int i = 0; i < m; i++)
        for (int j = 0; j < n; j++)
            vertical[i] += nm[j][i];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            cout << horizontal[i] + vertical[j] - nm[i][j] << ' ';
        cout << endl;
    }

    return 0;
}